package com.springboot.demo.design.pattern.factory;

import com.springboot.demo.design.pattern.Connection;

/**
 * 连接工厂
 *
 * @author supu
 * @date 2019-07-04 15:40
 **/
public class ConnectionFactory {
    private static final String DEFAULT_HOST = "localhost";
    private static final Integer DEFAULT_PORT = 8080;


    public static Connection getInstance() {
        return createConnection(DEFAULT_HOST, DEFAULT_PORT);
    }

    public static Connection getInstance(String host) {
        return createConnection(host, DEFAULT_PORT);
    }

    public static Connection getInstance(Integer port) {
        return createConnection(DEFAULT_HOST, port);
    }

    public static Connection getInstance(String host, Integer port) {
        return createConnection(host, port);
    }

    private static Connection createConnection(String host, Integer port) {
        return new Connection(host, port);
    }
}
